GetEventsAction   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 21
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A index 0 11 1
1
import { Controller, Inject, UseGuards, Get, Query } from '@nestjs/common';
2
import { AuthGuard } from '@nestjs/passport';
3
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
4
import { IQueryBus } from 'src/Application/IQueryBus';
5
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard';
6
import { Roles } from 'src/Infrastructure/User/Decorator/Roles';
7
import { UserRole } from 'src/Domain/User/User.entity';
8
import { EventView } from 'src/Application/Calendar/View/EventView';
9
import { GetEventsByPeriodQuery } from 'src/Application/Calendar/Query/GetEventsByPeriodQuery';
10
import { EventPeriodDTO } from '../DTO/EventPeriodDTO';
11
12
@Controller('events')
13
@ApiTags('Calendar')
14
@ApiBearerAuth()
15
@UseGuards(AuthGuard('bearer'), RolesGuard)
16
export class GetEventsAction {
17
  constructor(
18
    @Inject('IQueryBus')
19
    private readonly queryBus: IQueryBus
20
  ) {}
21
22
  @Get()
23
  @Roles(UserRole.PHOTOGRAPHER)
24
  @ApiOperation({ summary: 'Get events by a range of dates' })
25
  public async index(
26
    @Query() { fromDate, toDate }: EventPeriodDTO,
27
  ): Promise<EventView> {
28
    return await this.queryBus.execute(
29
      new GetEventsByPeriodQuery(
30
        new Date(fromDate),
31
        new Date(toDate)
32
      )
33
    );
34
  }
35
}
36